using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using QuanLy.Class;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Common;
using WoodManager.Header;

namespace WoodManager.UI
{
    public partial class FormReport : Form
    {
        ConnectManager cm = new ConnectManager();
        Validator vali = new Validator();
        DataSet ds;
        public DataTable tbSource, tbTongHopVan, tbTHSon;
        public string sLoaiReport;
        public string sDonHang ,sMaDH, sTenHMSP, sMaHMSP, sKichThuoc , sSoLuong, sNguoiDeXuat, sVersion, sNgayDeXuat, sNgayHoanThanh;

        public FormReport(string loaiReport)
        {
            InitializeComponent();
            sLoaiReport = loaiReport;
        }

        public FormReport()
        {
            InitializeComponent();
        }

        private void FormReport_Load(object sender, EventArgs e)
        {
            loadDeXuatVan(sLoaiReport);
        }

        private void addParameter(string sValue, string paraName, ref ReportDocument phieuDxv)
        {
            ParameterValues a = new ParameterValues();
            ParameterDiscreteValue b = new ParameterDiscreteValue();
            b.Value = sValue;
            a.Add(b);
            phieuDxv.DataDefinition.ParameterFields[paraName].ApplyCurrentValues(a);

        }
        public void loadDeXuatVan( String nameReport )
        {
            ReportDocument phieuDxv = new ReportDocument();
            switch ( sLoaiReport )
            {
                case WoodManagerHeader.RP_NAME_DXV_THANH_PHAN:
                    {
                        phieuDxv.Load(WoodManagerHeader.PATH_REPORT_DEXUATVAN_TP);
                        phieuDxv.SetDataSource(tbSource);
                        break;
                    }

                case WoodManagerHeader.RP_NAME_DXV_LOAI_VAN:
                    {
                        phieuDxv.Load(WoodManagerHeader.PATH_REPORT_DEXUATVAN_LV);
                        phieuDxv.SetDataSource(tbSource);
                        break;
                    }

                case WoodManagerHeader.RP_NAME_DXV_TH_VAN:
                    {
                        phieuDxv.Load(WoodManagerHeader.PATH_REPORT_DEXUATVAN_TH_VAN);
                        phieuDxv.SetDataSource(tbTongHopVan);
                        break;
                    }
                case WoodManagerHeader.RP_NAME_DXV_TH_SON:
                    {
                        phieuDxv.Load(WoodManagerHeader.PATH_REPORT_DEXUATVAN_TH_SON);
                        phieuDxv.SetDataSource(tbTHSon);
                        break;
                    }

            }
            addParameter(sDonHang, "DonHang", ref phieuDxv);
            addParameter(sMaDH, "MaDH", ref phieuDxv);
            addParameter(sTenHMSP, "TenSP", ref phieuDxv);
            addParameter(sMaHMSP, "MSSP", ref phieuDxv);
            addParameter(sKichThuoc, "KichThuoc", ref phieuDxv);
            addParameter(sSoLuong, "SoLuongSP", ref phieuDxv);
            addParameter(sNgayDeXuat, "NgayTK", ref phieuDxv);
            addParameter(sNgayHoanThanh, "NgayHoanThien", ref phieuDxv);
            addParameter(sNguoiDeXuat, "NguoiLap", ref phieuDxv);
            addParameter(sVersion, "Version", ref phieuDxv);

            //phieuDxv.SetDatabaseLogon("sa","12345","Giang-PC\\SQL2005","QuanLyNK");
            CrpViewer.ReportSource = phieuDxv;
            CrpViewer.Show();
        }
    }
}